package com.edu.order.service.impl;

import com.api.sso.SSOClient;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.edu.entity.HfdLocInfo;
import com.edu.entity.HfdUserInfo;
import com.edu.interceptor.UserInfoInterceptor;
import com.edu.order.mapper.HfdLocInfoMapper;
import com.edu.order.service.IHfdLocInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地址表 服务实现类
 * </p>
 *
 * @author jr
 * @since 2021-04-14
 */
@Service
public class HfdLocInfoServiceImpl extends ServiceImpl<HfdLocInfoMapper, HfdLocInfo> implements IHfdLocInfoService {

    @Autowired(required = false)
    private HfdLocInfoMapper hfdLocInfoMapper;

    @Autowired
    private SSOClient sSOClient;

    //添加地址
    @Override
    public Result addLoc(HfdLocInfo hfdLocInfo) {

        int b = hfdLocInfoMapper.insert(hfdLocInfo);
        return new Result(true,90011,"success");
    }

    //删除地址
    @Override
    public Result deleteAddress(Integer locId) {
        int i = hfdLocInfoMapper.deleteById(locId);
        return new Result(true,90031,"success");
    }

    @Override
    public Result findLoc() {

        //获取用户信息
        HfdUserInfo userInfo = UserInfoInterceptor.getUserInfo();
//        HfdUserInfo userInfo =  new HfdUserInfo();
//        userInfo.setUserId(1);

        //获取地址信息
        QueryWrapper<HfdLocInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userInfo.getUserId());

        List<HfdLocInfo> hfdLocInfos = hfdLocInfoMapper.selectList(queryWrapper);
        return new Result(true,90041,"success",hfdLocInfos);
    }
}
